﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace huaguwang
{
    public class D_T_RealBook_Exp : D_T_RealBook
    {
        /// <summary>
        /// 得到一个对象实体
        /// 带有flag标签条件的
        /// </summary>
        public huaguwang.M_T_RealBook GetModelFlagExp(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,Title,EbookID,ISBN,Publish,Author,Explain,Pic,Price,Gold,Grade,Click,WebTitle,WebSummary,WebKey,InnerKey,ColorTitle,ColorKey,SellNum,StockNum,RemSign,Topis,Flag from T_RealBook ");
            strSql.Append(" where EbookID=@id and Flag=1 ");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
            parameters[0].Value = id;

            huaguwang.M_T_RealBook model = new huaguwang.M_T_RealBook();
            DataSet ds = MSSQLHelper.SQLConType.C1.Exp_Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                if (ds.Tables[0].Rows[0]["EbookID"].ToString() != "")
                {
                    model.EbookID = int.Parse(ds.Tables[0].Rows[0]["EbookID"].ToString());
                }
                model.ISBN = ds.Tables[0].Rows[0]["ISBN"].ToString();
                model.Publish = ds.Tables[0].Rows[0]["Publish"].ToString();
                model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                model.Explain = ds.Tables[0].Rows[0]["Explain"].ToString();
                model.Pic = ds.Tables[0].Rows[0]["Pic"].ToString();
                if (ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Gold"].ToString() != "")
                {
                    model.Gold = decimal.Parse(ds.Tables[0].Rows[0]["Gold"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Grade"].ToString() != "")
                {
                    model.Grade = int.Parse(ds.Tables[0].Rows[0]["Grade"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Click"].ToString() != "")
                {
                    model.Click = int.Parse(ds.Tables[0].Rows[0]["Click"].ToString());
                }
                model.WebTitle = ds.Tables[0].Rows[0]["WebTitle"].ToString();
                model.WebSummary = ds.Tables[0].Rows[0]["WebSummary"].ToString();
                model.WebKey = ds.Tables[0].Rows[0]["WebKey"].ToString();
                model.InnerKey = ds.Tables[0].Rows[0]["InnerKey"].ToString();
                model.ColorTitle = ds.Tables[0].Rows[0]["ColorTitle"].ToString();
                model.ColorKey = ds.Tables[0].Rows[0]["ColorKey"].ToString();
                if (ds.Tables[0].Rows[0]["SellNum"].ToString() != "")
                {
                    model.SellNum = int.Parse(ds.Tables[0].Rows[0]["SellNum"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StockNum"].ToString() != "")
                {
                    model.StockNum = int.Parse(ds.Tables[0].Rows[0]["StockNum"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RemSign"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["RemSign"].ToString() == "1") || (ds.Tables[0].Rows[0]["RemSign"].ToString().ToLower() == "true"))
                    {
                        model.RemSign = true;
                    }
                    else
                    {
                        model.RemSign = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Topis"].ToString() != "")
                {
                    model.Topis = int.Parse(ds.Tables[0].Rows[0]["Topis"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Flag"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Flag"].ToString() == "1") || (ds.Tables[0].Rows[0]["Flag"].ToString().ToLower() == "true"))
                    {
                        model.Flag = true;
                    }
                    else
                    {
                        model.Flag = false;
                    }
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 逻辑删除一条资料
        /// </summary>
        public int UpdateFlagExp(int EbookID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_RealBook ");
            strSql.Append(" set flag=0 where EbookID=@EbookID");
            SqlParameter[] parameters = {
					new SqlParameter("@EbookID", SqlDbType.Int,4)};
            parameters[0].Value = EbookID;
            int rows = MSSQLHelper.SQLConType.C1.Exp_ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return EbookID;
            }
            else
            {
                return 0;
            }
        }
    }
}
